﻿

Public Class PanelBuffering
    'Fields :
    Private _LocalBuffering As New Buffering
    Private _TargetNode As ZipNode
    Public WriteOnly Property TargetNode As ZipNode
        Set(value As ZipNode)
            _TargetNode = value
            _LocalBuffering.CopyFrom(_TargetNode.ZipSettings.Buffering)
            ShowBuffering()
        End Set
    End Property
    'Show Settings :
    Private Sub ShowBuffering()
        Me.SuspendLayout()
        KCB_IOBS.SelectedItem = CStr(_LocalBuffering.IOBS)
        KCB_ZCBS.SelectedItem = CStr(_LocalBuffering.ZCBS)
        KCB_PDT.SelectedItem = CStr(_LocalBuffering.PDT)
        KCB_PDMBP.SelectedItem = CStr(_LocalBuffering.PDMBP / 2)
        Me.ResumeLayout()
    End Sub
    'Selections :
    Private Sub KCB_IOBS_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles KCB_IOBS.SelectedIndexChanged
        KL_IOBS_Value.Text = StringFromSize(CInt(KCB_IOBS.SelectedItem), 0)
    End Sub
    Private Sub KCB_ZCBS_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles KCB_ZCBS.SelectedIndexChanged
        KL_ZCBS_Value.Text = StringFromSize(CInt(KCB_ZCBS.SelectedItem), 0)
    End Sub
    Private Sub KCB_PDT_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles KCB_PDT.SelectedIndexChanged
        Select Case KCB_PDT.SelectedIndex
            Case 0
                KL_PDT_Value.Text = "Never"
            Case 1
                KL_PDT_Value.Text = "Always"
            Case Else
                KL_PDT_Value.Text = StringFromSize(CLng(KCB_PDT.SelectedItem), 0)
        End Select
    End Sub
    Private Sub KCB_PDMBP_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles KCB_PDMBP.SelectedIndexChanged
        KL_PDMBP_Value.Text = CStr(CInt(KCB_PDMBP.SelectedItem) * 2) & " Buffs"
    End Sub
    'Resets :
    Private Sub BSA_Reset_IOBS_Click(sender As Object, e As System.EventArgs) Handles BSA_Reset_IOBS.Click
        KCB_IOBS.SelectedItem = CStr(Buffering.Defaults.IOBS)
    End Sub
    Private Sub BSA_Reset_ZCBS_Click(sender As Object, e As System.EventArgs) Handles BSA_Reset_ZCBS.Click
        KCB_ZCBS.SelectedItem = CStr(Buffering.Defaults.ZCBS)
    End Sub
    Private Sub BSA_Reset_PDT_Click(sender As Object, e As System.EventArgs) Handles BSA_Reset_PDT.Click
        KCB_PDT.SelectedItem = CStr(Buffering.Defaults.PDT)
    End Sub
    Private Sub BSA_Reset_PDMBP_Click(sender As Object, e As System.EventArgs) Handles BSA_Reset_PDMBP.Click
        KCB_PDMBP.SelectedItem = CStr(Buffering.Defaults.PDMBP / 2)
    End Sub
    'Actions:
    Public Sub Reset()
        _LocalBuffering.Reset()
        ShowBuffering()
    End Sub
    Public Sub Cancel()
        _LocalBuffering.CopyFrom(_TargetNode.ZipSettings.Buffering)
        ShowBuffering()
    End Sub
    Public Sub Apply()
        _TargetNode.ZipSettings.Buffering.IOBS = CInt(KCB_IOBS.SelectedItem)
        _TargetNode.ZipSettings.Buffering.ZCBS = CInt(KCB_ZCBS.SelectedItem)
        _TargetNode.ZipSettings.Buffering.PDT = CLng(KCB_PDT.SelectedItem)
        _TargetNode.ZipSettings.Buffering.PDMBP = CInt(KCB_PDMBP.SelectedItem) * 2
        Me.TargetNode = _TargetNode
    End Sub

End Class
